﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ElteIk.RoboSoccer.Logger
{
    public class Log
    {
        private List<LogItem> logItems;
        public List<LogItem> LogItems
        {
            get { return logItems; }
            set { logItems = value; }
        }

        private string logFileName;
        public string LogFileName
        {
            get { return logFileName; }
            set { logFileName = value; }
        }

        public Log()
        {
            logItems = new List<LogItem>();
            logFileName = "Log.log";
        }

        public Log(string fileName)
        {
            logItems = new List<LogItem>();
            logFileName = fileName;
        }

        public void Add(string log)
        {
            logItems.Add(new LogItem(log));
        }

        public List<LogItem> GetItemsInDateTimeRange(DateTime from, DateTime to)
        {
            List<LogItem> items = new List<LogItem>();
            foreach (LogItem item in logItems)
                items.Add(new LogItem(item.DateTime, item.Log));
            return items;
        }

        public void WriteOut(string fileName)
        {
            logFileName = fileName;
            WriteOut();
        }

        public void WriteOut()
        {
            StreamWriter LogFile = new StreamWriter(logFileName, true);
            for (int i = 0; i < logItems.Count; i++)
                LogFile.WriteLine(logItems[i].ToString());
            LogFile.Close();
        }
    }
}
